package org.huangrui.juc.source.cf;

import java.util.concurrent.*;

/**
 * @Author hr
 * @Create 2024-04-01 05:03
 */
public class T04_CompletableFutureAPI {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService threadPool = Executors.newFixedThreadPool(3);
        CompletableFuture<Void> runAsync = CompletableFuture.runAsync(() -> {
             System.out.println(Thread.currentThread().getName()+"\t -----come in");
        },threadPool);

        System.out.println(runAsync.get());

        CompletableFuture<String> async = CompletableFuture.supplyAsync(() -> {
             System.out.println(Thread.currentThread().getName()+"\t -----come in");
             //暂停几毫秒
             try { TimeUnit.MILLISECONDS.sleep(300);} catch (InterruptedException e) {e.printStackTrace();}
            return "t1...supplyAsync";
        },threadPool);
        System.out.println(async.get());
        threadPool.shutdown();
    }
}
